Imports System.Data

Partial Class WebForms_SearchCIssues
    Inherits WebFormCommon

    Dim strPath As String

    Private Sub SecurePage()
        Dim sec As New Secure

        With sec
            .ParentPage = ParentPage
            .AddControl(Print_btn, Secure.ControlTypes.PrintType)
            .AddControl(Save_btn, Secure.ControlTypes.PrintType)
            .AddDataGridColumn(DataGrid, DataGrid.Columns.Count - 2, Secure.ControlTypes.DeleteType)
            .AddDataGridColumn(DataGrid, DataGrid.Columns.Count - 3, Secure.ControlTypes.EditType)
            .SetPageAccess(Session("UserName"))
        End With

        sec = Nothing
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Call SecurePage()

        Select Case Me.PageControlMode
            Case ControlMode.NewBusiness
                strPath = "New_Business"
                Refferal_lbl.Visible = False
                Search_Referrals.Visible = False
            Case ControlMode.ClientServicing
                strPath = "Client_Servicing"
        End Select

        If Not Page.IsPostBack Then
            Call Search()
        End If


    End Sub

    Protected Sub Search_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Search_btn.Click
        Call Search()
    End Sub

    Private Sub Search()
        Dim dao As New DAOMain.VW_POLICY_ISSUE_DTL_SEARCH_DAO
        Dim vo As New DAOMain.VW_POLICY_ISSUE_DTL_SEARCH_VO
        Dim cf As New CIMSfunc

        With vo
            .POLICY_NO = "%" & Policynumber_txt.Text & "%"
            .PROVIDER_DESC = "%" & Provider_txt.Text & "%"
            .PRDT_DESC = "%" & Product_txt.Text & "%"
            .POLICY_CLIENT_FIRST_NAME = "%" & Name_txt.Text & "%"
            .POLICY_CLIENT_LAST_NAME = "%" & Last_Name_txt.Text & "%"
            If Date_txt.Text <> "" Then .POLICY_ISSUE_DT = cf.ParseSetDate(Date_txt.Text)
            .STATUS = "%" & Status_txt.Text & "%"

            If Not IsNothing(Session("advisor")) Then
                .ADVISOR = Session("UserName") & "%"
            End If

            Select Case Me.PageControlMode
                Case ControlMode.ClientServicing
                    .PROCESS_ST = "%CS%"
                Case ControlMode.NewBusiness
                    .PROCESS_ST = "%NB%"
            End Select

            Dim dt As DataTable = dao.Search(vo, , True)
            results_label.Text = dt.Rows.Count

            ViewState.Add("dtable", dt)
            DataGrid.CurrentPageIndex = 0
            DataGrid.DataSource = ViewState("dtable")
            DataGrid.DataBind()
        End With

        cf = Nothing
        dao = Nothing
        vo = Nothing
    End Sub

    Protected Sub DataGrid_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid.ItemCommand
        If e.Item.ItemType = ListItemType.Item Then
            Select Case e.CommandName
                Case "Edit", "View"
                    Session.Add("Seq_CD", e.Item.Cells(0).Text)
                    Session.Add("CID", e.Item.Cells(1).Text)
                    Session.Add("PolicyNo", e.Item.Cells(2).Text)
                    Session.Add("Provider", e.Item.Cells(6).Text & " - " & e.Item.Cells(7).Text)
                    Session.Add("PageSource", "SearchIssues")
                    Session.Add("mode", "edit")

                    Response.Redirect("~/" & strPath & "/Add_CIssue.aspx")
                Case "View"

                    Session.Add("Seq_CD", e.Item.Cells(0).Text)
                    Session.Add("CID", e.Item.Cells(1).Text)
                    Session.Add("PolicyNo", e.Item.Cells(2).Text)
                    Session.Add("Provider", e.Item.Cells(6).Text & " - " & e.Item.Cells(7).Text)
                    Session.Add("PageSource", "SearchIssues")
                    Session.Add("mode", "view")

                    Response.Redirect("~/" & strPath & "/Add_CIssue.aspx")
            End Select
        End If
    End Sub

    'Protected Sub DataGrid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid.ItemDataBound
    '    Dim cf As New CIMSfunc

    '    If e.Item.ItemType = ListItemType.Item Then
    '        e.Item.Cells(4).Text = cf.ParseGetDate(Format(CDate(e.Item.Cells(4).Text), "MM/dd/yyyy"))
    '    End If

    '    cf = Nothing
    'End Sub

    Protected Sub Search_Policies_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Search_Policies.Click
        Response.Redirect("~/" & strPath & "/Search_Policies.aspx")
    End Sub

    Protected Sub Search_Referrals_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Search_Referrals.Click
        Response.Redirect("~/" & strPath & "/Search_Referrals.aspx")
    End Sub

    Protected Sub DataGrid_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid.PageIndexChanged
        If Not IsNothing(ViewState("dtable")) Then
            If DataGrid.PageCount >= e.NewPageIndex Then
                DataGrid.CurrentPageIndex = e.NewPageIndex
                DataGrid.DataSource = ViewState("dtable")
                DataGrid.DataBind()
            End If
        End If
    End Sub

    Protected Sub Save_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Save_btn.Click
        'PolicyIssueExport.rpt

        Dim crpt As New CReports

        With crpt
            If Not IsNothing(ViewState("dtable")) Then
                Dim dt As DataTable = ViewState("dtable")

                .ShowRpt("PolicyIssueExport", CReports.RptType.Excel_Report, ParentPage, dt, "vw_policy_issue_dtl_search")
            End If
        End With

        crpt = Nothing
    End Sub

End Class
